package vip.aster.workflow.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * 流程枚举类
 *
 * @author Aster lipian1004@163.com
 * @since 2024-04-09 11:36:12
 */
public class ProcessEnum {

    /**
     * 节点枚举类
     */
    @Getter
    @AllArgsConstructor
    public enum NodeEnum {
        START("start", "开始"),
        END("end", "结束"),
        ;

        /**
         * 名称
         */
        private final String name;

        /**
         * value
         */
        private final String value;

        public static String message(String name) {
            if (!StringUtils.isBlank(name)) {
                NodeEnum[] values = values();
                for (NodeEnum nodeEnum : values) {
                    if (nodeEnum.getValue().equals(name)) {
                        return nodeEnum.name();
                    }
                }
            }
            return StringUtils.EMPTY;
        }
    }

    /**
     * 流程状态枚举类
     */
    @Getter
    @AllArgsConstructor
    public enum ProcessStatusEnum {

        PROCESS_START("process-start", "流程启动"),
        PROCESS_END("process-end", "流程结束"),
        ;

        /**
         * 值
         */
        private final String value;

        /**
         * 文本
         */
        private final String text;

        public static String message(String name) {
            if (!StringUtils.isBlank(name)) {
                ProcessStatusEnum[] values = values();
                for (ProcessStatusEnum processStatusEnum : values) {
                    if (processStatusEnum.getValue().equals(name)) {
                        return processStatusEnum.name();
                    }
                }
            }
            return StringUtils.EMPTY;
        }

    }

    /**
     * 节点类型枚举类
     */
    public enum NodeTypeEnum {
        ROOT, APPROVAL, TASK, SEND, CONDITIONS, CONCURRENTS, CONDITION, INCLUSIVES, INCLUSIVE, CONCURRENT, DELAY, TRIGGER, EMPTY
    }

    @Getter
    @AllArgsConstructor
    public enum WebNodeTypeEnum {

        ROOT("0", "根节点"),
        APPROVAL("1", "审批节点"),
        SEND("2", "抄送"),
        CONDITIONS("3", "条件"),
        ;

        /**
         * 节点类型
         */
        private final String value;

        /**
         * 文本
         */
        private final String text;
    }

    /**
     * 节点类型枚举类
     */
    @Getter
    @AllArgsConstructor
    public enum NodeSetTypeEnum {

        ASSIGNEE("1", "指定成员"),
        CHARGE("2", "主管"),
        SEND("4", "发起人自选"),
        MINE("5", "发起人自己"),
        MORE_CHARGE("7", "连续多级主管"),
        ;

        /**
         * 名称
         */
        private final String type;

        /**
         * value
         */
        private final String value;

    }

    /**
     * 表单状态枚举类
     */
    @Getter
    @AllArgsConstructor
    public enum FormStatusEnum {

        DRAFT("-1", "暂存"),
        START("0", "开始"),
        PASS("1", "通过"),
        REJECT("2", "驳回"),
        END("9", "完成"),
        ;

        /**
         * value
         */
        private final String value;

        /**
         * 名称
         */
        private final String text;

        public static String message(String value) {
            if (!StringUtils.isBlank(value)) {
                FormStatusEnum[] values = values();
                for (FormStatusEnum formStatusEnum : values) {
                    if (formStatusEnum.getValue().equals(value)) {
                        return formStatusEnum.getText();
                    }
                }
            }
            return StringUtils.EMPTY;
        }
    }

    /**
     * 表单控件枚举类
     */
    public enum FormComponentEnum {
        GridTitle, GridLayout, TableList, Description, InputText, InputTextarea, InputNumber, InputAmount, SelectSingle, SelectMultiple,
        DateTime, DateTimeRange, UploadImage, UploadFile, UserPicker, DeptPicker, Rate, SerialNumber, AssociatedForm, GeoLocation, Area,
        Signature, AssociatedProcess, CalcFormula, CalcFormulaAdvanced;

        public static List<String> getList() {
            FormComponentEnum[] values = values();
            return Arrays.stream(values).map(Enum::toString).toList();
        }

        public static List<String> getNotFieldList() {
            return Arrays.asList(GridTitle.toString(), GridLayout.toString(), TableList.toString());
        }

    }


}
